<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Three_TDT</title>
    <script src="/Public/js/tianditu.api.js"></script>
    <script src="/Public/js/jquery-3.7.1.min.js"></script>
    <script src="/Public/js/geoTools.js"></script>
    <script src="/Public/js/f3d.js"></script>
    <link rel="icon" href="/Public/imgs/H.ico">
    <link rel="stylesheet" href="/Public/css/0912.css">
    <style>
        html,
        body {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }

        #map {
            position: relative;
            width: 100%;
            height: 100%;
            cursor: default;
        }

        #getDem {
            position: absolute;
            bottom: 100px;
            left: 20px;
            z-index: 450;
            width: 50px;
            height: 200x;
        }
    </style>
</head>

<body>
    <div id="map"></div>
    <button id="getDem">T</button>
    <div id="coordSwitchButton">
        <span>显示坐标</span>
        <button class="switch">
            <span class="switch_circle circle_left"></span>
        </button>
    </div>

    <div id="coordInfoContainer">
        <span id="coord"></span>
    </div>
    <script>
        let geo_marker_list = []

        var map = new T.Map('map', { tileSize: 512 });
        //禁用双击放大
        map.disableDoubleClickZoom()
        map.centerAndZoom(new T.LngLat(103.07587, 29.96848), 14);
        var ctrl = new T.Control.MapType(
            { position: T_ANCHOR_BOTTOM_RIGHT }
        );
        map.addControl(ctrl);

        //显示坐标功能
        regShowCoord(map);

        const river_list = []
        $.get('http://localhost:8080/localGEO/getYARiver').then(res => {
            res.forEach(riv => {
                const coord_json = JSON.parse(riv.geometry).coordinates
                const riv_name = riv.name
                var points = []
                coord_json.forEach(p => {
                    points.push(new T.LngLat(p[0], p[1]))
                })
                var line = new T.Polyline(points, {
                    color: 'red',
                    weight: 0.8,
                    opacity: 0.8,
                    lineStyle: "dash",
                });
                map.addOverLay(line);
                river_list.push([line, riv_name])
            })
        })

        var recTool = new T.RectangleTool(map, {
            showLabel: false,
            fillColor: 'green',
            fillOpacity: 0.001
        });;

        $('#getDem').on('click', HD1)

        async function HD1() {
            geo_marker_list.forEach(o => {
                map.removeOverLay(o)
            })
            geo_marker_list = []

            recTool.removeEventListener('draw');
            recTool.clear();
            recTool.open();
            const bbox_geo = await getBbox()
            // const riv_ins = cal_riv_intersects(river_list,bbox_geo)
            const riv_ins = cal_riv_intersects(river_list,bbox_geo)
            
        }




        
    </script>
</body>

</html>